﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace GDCal
{
    public class GDCalUtils
    {
        public static bool isValueEmpty(String valueToCheck, String message, String caption)
        {
            Boolean ret = false;
            if (String.IsNullOrEmpty(valueToCheck))
            {
                ret = true;
                MessageBox.Show(message, caption);
            }
            return ret;
        }

        public static Dictionary<String, String> ReadDictionaryFile(String fileName)
        {
            Dictionary<String, String> dictionary = new Dictionary<String, String>();
            
            foreach (String line in File.ReadAllLines(fileName))
            {
                if ((!String.IsNullOrEmpty(line)) &&
                    (!line.StartsWith(";")) &&
                    (!line.StartsWith("#")) &&
                    (!line.StartsWith("'")) &&
                    (line.Contains('=')))
                {
                    int index = line.IndexOf('=');
                    String key = line.Substring(0, index).Trim();
                    String value = line.Substring(index + 1).Trim();

                    if ((value.StartsWith("\"") && value.EndsWith("\"")) ||
                        (value.StartsWith("'") && value.EndsWith("'")))
                    {
                        value = value.Substring(1, value.Length - 2);
                    }
                    dictionary.Add(key, value);
                }
            }

            return dictionary;
        }
    }
}
